home *** CD-ROM | disk | FTP | other *** search
/ Professional Soft Collection 1.02 / Professional Soft Collection 1.02.iso / winutils / wingauge.zip / INTEGR5.C < prev    next >
C/C++ Source or Header  |  1993-01-19  |  4KB  |  115 lines

  1. #pragma hdrfile "WinGauge.SYM"
  2. #include <win31.h>
  3. #include "wingauge.h"
  4. #include "wingauge.rh"
  5. #pragma hdrstop
  6.  
  7. #include <stdlib.h>
  8.  
  9. static    void    PaintBorder( HDC, short ), PaintPanel( short, HDC, short );
  10.  
  11.  
  12. /*--------------------==================================--------------------*/
  13. /*         Proceed WM_DRAWITEM message -- draw owner-drawed button        */
  14. /*--------------------==================================--------------------*/
  15.  
  16. void DrawButton( LPDRAWITEMSTRUCT lpDIS, WORD wCheck )
  17. { register HDC    hDC = lpDIS->hDC;
  18.   HPEN          hPen;
  19.  
  20.   SaveDC( hDC );                // Windows requires this
  21.  
  22.                         // Draw focus rectangle
  23.   SelectObject( hDC, GetStockObject(NULL_BRUSH) );     // Don't erase interior
  24.   hPen = SelectObject( hDC, CreatePen( PS_SOLID, 1,    // Select color
  25.                     (lpDIS->itemState & ODS_FOCUS ?
  26.                                BLACK : LIGHTGRAY) ) );
  27.   Rectangle( hDC, 0, 0, 40, 40 );                      // Draw rectangle
  28.   DeleteObject( SelectObject( hDC, hPen ) );           // Clearance
  29.  
  30.   if( lpDIS->itemAction != ODA_FOCUS )        // We must draw entire button
  31.     { short i;                    // State of button:
  32.       i = ( (lpDIS->itemState & ODS_SELECTED) ? 4 :    // it is pushing now,
  33.             lpDIS->CtlID == wCheck ? 3 :   // it is turned on,
  34.                           2 ); // it is turned off.
  35.       PaintPanel( lpDIS->CtlID, hDC, i+2 );    // Draw button surface
  36.  
  37.       if( i == 2 )                // Now draw border of button
  38.     PaintBorder( hDC, 2 );
  39.       else
  40.     { hPen = SelectObject( hDC, CreatePen(PS_SOLID, 1, DARKGRAY) );
  41.       while( --i )
  42.         { MoveTo(hDC,i+2,36); LineTo(hDC,i+2,i+2); LineTo(hDC,36,i+2); }
  43.       DeleteObject( SelectObject( hDC, hPen ) );
  44.     }
  45.       Rectangle( hDC, 2, 2, 38, 38 );
  46.     }
  47.  
  48.   RestoreDC( hDC, -1 );                // Restore old (last saved) DC
  49. }
  50.  
  51.  
  52. /*--------------------==================================--------------------*/
  53. /*              Draw "turned off" 3-D button border            */
  54. /*--------------------==================================--------------------*/
  55.  
  56. static void PaintBorder( HDC hDC, short sOffset )
  57. { register short s1  = sOffset + 1,            // For optimization
  58.          s34 = sOffset + 34;                //  and simplification
  59.   HPEN hPen;
  60.  
  61.   hPen = SelectObject( hDC, CreatePen(PS_SOLID, 1, DARKGRAY) );
  62.   MoveTo( hDC, s34, s1 ); LineTo( hDC, s34, s34 ); LineTo( hDC, s1, s34 );
  63.   DeleteObject( SelectObject( hDC, GetStockObject(WHITE_PEN) ) );
  64.   MoveTo( hDC, s1, s34 ); LineTo( hDC, s1, s1 ); LineTo( hDC, s34, s1 );
  65.   SelectObject( hDC, hPen );
  66. }
  67.  
  68.  
  69. /*--------------------==================================--------------------*/
  70. /*               Draw interior of gauge                */
  71. /*--------------------==================================--------------------*/
  72.  
  73. static void PaintPanel( short sPanel, HDC hDC, short sOffset )
  74. { HDC  hMemDC;
  75.   char cBuffer[6];
  76.  
  77.   hMemDC = CreateCompatibleDC( hDC );            // Draw button bitmap
  78.   SelectObject( hMemDC, ahBitmaps[sPanel] );
  79.   BitBlt( hDC, sOffset, sOffset, 32, 32, hMemDC, 0, 0, SRCCOPY );
  80.   DeleteDC( hMemDC );
  81.  
  82.   lstrcat( itoa( awNew[sPanel], cBuffer, 10 ), "%" );             // Prepare text
  83.   (*afnPaint[sPanel])( hDC, sOffset, awNew[sPanel], cBuffer ); // Fill bitmap
  84.   SetTextAlign( hDC, TA_CENTER );                              // Prepare DC
  85.   SetBkMode( hDC, TRANSPARENT );
  86.   TextOut( hDC, sOffset+15, sOffset-2,
  87.        cBuffer, lstrlen( cBuffer ) );               // Draw text
  88. }
  89.  
  90.  
  91. /*--------------------==================================--------------------*/
  92. /*           Draw working gauge or integrating icon as an icon        */
  93. /*--------------------==================================--------------------*/
  94.  
  95. void PaintIcon( HWND hWnd, short sPanel )
  96. { HDC    hDC;
  97.   PAINTSTRUCT ps;
  98.  
  99.   hDC = BeginPaint( hWnd, &ps );
  100.  
  101.   SelectObject( hDC, GetStockObject(NULL_BRUSH) );    // Do not erase
  102.   Rectangle( hDC, 0, 0, 36, 36 );            //  rectangle interior
  103.   PaintBorder( hDC, 0 );                // Draw 3-D border
  104.  
  105.   if( sPanel == 0 )                    // Draw only icon
  106.     { HICON hIcon = LoadIcon( hInst, MAKEINTRESOURCE(1) );
  107.       DrawIcon( hDC, 2, 2, hIcon );
  108.       FreeResource( hIcon );
  109.     }
  110.   else                            // Draw panel
  111.     PaintPanel( sPanel, hDC, 2 );
  112.  
  113.   EndPaint( hWnd, &ps );
  114. }
  115.